﻿using System;
using DotNetNinjaLibrary.Basics;

namespace DotNetNinjaLibrary.Actions
{
	public class MoveAction : IUnitAction
	{
		private Unit target;
		private Point destination;

		// TODO: Make it use directions instead of concrete points.
		public MoveAction(Unit target, Point destination)
		{
			this.target = target;
			this.destination = destination;
		}

		public bool CanExecute()
		{
			return this.target.Map != null && this.target.Map.IsMovePossible(this.destination, this.target.Size);
		}

		public void Execute()
		{
			this.target.MoveTo(this.destination);
		}

		public long TimeNeeded
		{
			get { return (int)MathsHelper.GetDirection(this.target.Location, this.destination) % 2 == 0 ? this.target.Speed : MathsHelper.TimeForDiagonal(this.target.Speed); }
		}
	}
}